package com.xq.tmall.agu.job.impl;


import com.xq.tmall.agu.ferign.IpValidSpider;
import com.xq.tmall.agu.ferign.StockHistorySpider;
import com.xq.tmall.agu.job.AbstractTimeJob;
import com.xq.tmall.container.SimpleTimerJobContainer;
import com.xq.tmall.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class IPTimerJobImpl extends AbstractTimeJob {

    private SimpleTimerJobContainer ipTimerJob;

    public IPTimerJobImpl() {
        name = "校验ip是否有效";
    }

    @Override
    public void execute(COMMAND command) {
        switch (command){
            case START:
                if (null == ipTimerJob) {
                    log.info("开启校验ip是否有效!");
                    IpValidSpider ipValidSpider = SpringContextUtil.getBean(IpValidSpider.class);
                    ipTimerJob = new SimpleTimerJobContainer(ipValidSpider,0,10, TimeUnit.MINUTES,"ipValidSpider",2);
                    new Thread(ipTimerJob, "ipTimerJob").start();
                    status=STATUS.RUN;
                }
                break;
            case STOP:
                if (null != ipTimerJob) {
                    log.info("关闭校验ip是否有效!");
                    ipTimerJob.shutDown();
                    ipTimerJob = null;
                    status=STATUS.STOP;
                }
                break;
        }
    }
}
